home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Procedure to decode incoming packets from the PK232 *)
- (* *)
- (* Copyright 1988, 1989, 1990 by H. Roy Engehausen. All rights reserved. *)
- (* This software may be freely distributed and used, but it may not *)
- (* under any circumstances be sold by anyone other than the author. *)
- (* It may be distributed by a commercial company as long as it is *)
- (* for no cost. *)
- (* *)
- (*===========================================================================*)
-
- PROCEDURE pk232_decode;
-
- VAR
- i : BYTE;
-
- BEGIN;
-
- WITH active_tcb^, active_tcb^.tnc_data, pk232_buff^ DO
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* Extract the channel and type codes *)
- (*-------------------------------------------------------------------*)
-
- pk232_chan := (pk232_ctl AND $0F) + 1;
- IF pk232_chan > 9 THEN
- pk232_chan := 0;
-
- i := pk232_ctl AND $F0;
-
- (*-------------------------------------------------------------------*)
- (* Handle a null poll response *)
- (*-------------------------------------------------------------------*)
-
- IF (pk232_ctl = pk232_incoming_cmd) AND (tnc_cmd_data > 1) THEN
- BEGIN;
- tnc_type := t_to_h_ok;
- pk232_len := 0;
- pk232_chan := channel;
- EXIT;
- END;
-
- (*-------------------------------------------------------------------*)
- (* Handle a status response *)
- (*-------------------------------------------------------------------*)
-
- IF pk232_ctl = pk232_incoming_status THEN
- BEGIN;
-
- pk232_chan := channel;
-
- (*---------------------------------------------------------------*)
- (* Check for 5FXX *)
- (*---------------------------------------------------------------*)
-
- IF (pk232_dat[1] <> 'X') OR (pk232_dat[2] <> 'X') THEN
- BEGIN;
- window_write_critical_i('Non XX 5F received from PK232 -- '
- + port_chan_s + ' -- '
- + pk232_dat[1]
- + pk232_dat[2] + ' -- ',
- ORD(pk232_dat[3]));
- tnc_type := t_to_h_badmsg;
- EXIT;
- END;
-
- (*---------------------------------------------------------------*)
- (* Handle 5FXX *)
- (*---------------------------------------------------------------*)
-
- IF pk232_dat[3] <> #0 THEN
- tnc_type := t_to_h_badmsg
- ELSE
- BEGIN;
- tnc_type := t_to_h_ok;
- pk232_len := 0;
- active_port^.port_pk232_data_ack := FALSE;
-
- {$IFDEF DEBUG}
- WRITELN('5FXX0 received');
- {$ENDIF}
-
- END;
-
- EXIT;
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Incoming monitor data *)
- (*-------------------------------------------------------------------*)
-
- IF pk232_ctl = pk232_incoming_mon THEN
- BEGIN;
-
- {$IFDEF DEBUG}
- WRITELN('Incoming monitor data');
- {$ENDIF}
-
- pk232_chan := 0;
- tnc_type := t_to_h_mh_noi;
- EXIT;
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Handle incoming data *)
- (*-------------------------------------------------------------------*)
-
- IF i = pk232_incoming_data THEN
- BEGIN;
- tnc_type := t_to_h_conn;
- EXIT;
- END;
-
- (*-------------------------------------------------------------------*)
- (* Handle incoming link status *)
- (*-------------------------------------------------------------------*)
-
- IF i = pk232_incoming_link2 THEN
- BEGIN;
-
- {$IFDEF DEBUG}
- WRITELN('Link status -- ', channel, ' -- ', pk232_ctl);
- {$ENDIF}
-
- (*---------------------------------------------------------------*)
- (* Clean things up *)
- (*---------------------------------------------------------------*)
-
- tnc_type := t_to_h_links;
-
- IF (pk232_len >= 3) AND (pk232_len < 259) THEN
- pk232_ctl := pk232_len - 3
- ELSE
- pk232_ctl := 1;
-
- strip_crlf(pk232_str);
-
- (*---------------------------------------------------------------*)
- (* Translate DISCONNECT message *)
- (*---------------------------------------------------------------*)
-
- IF subword(@pk232_str, 1, 1) = 'DISCONNECTED:' THEN
- pk232_str := t_to_h_disc + subword(@pk232_str, 2, 0);
-
- (*---------------------------------------------------------------*)
- (* Set length and done *)
- (*---------------------------------------------------------------*)
-
- pk232_len := LENGTH(pk232_str);
- IF pk232_len <= 252 THEN
- INC(pk232_len, 3);
-
- EXIT;
- END;
-
- (*-------------------------------------------------------------------*)
- (* All that should be left by now is command responses *)
- (*-------------------------------------------------------------------*)
-
- IF (pk232_ctl <> pk232_incoming_cmd) AND
- ((i <> $40) AND NOT l_switch) THEN
- window_write_critical_i('Didn''t handle PK232 Response -- '
- + port_chan_s + ' -- ',
- pk232_ctl);
-
- pk232_chan := channel;
-
- (*-------------------------------------------------------------------*)
- (* If we sent a command then we must interpret the responses *)
- (*-------------------------------------------------------------------*)
-
- IF tnc_cmd_data = info_cmd_cmd THEN
-
- IF pk232_dat[3] >= #$20 THEN (* More than $20 indicates a *)
- BEGIN; (* parameter response *)
- tnc_type := t_to_h_okmsg;
- IF l_switch THEN
- BEGIN;
-
- (*---------------------------------------------------------*)
- (* L response -- DED format is: *)
- (* Word 1 -- Number of link status messages waiting *)
- (* Word 2 -- Number of data packets waiting *)
- (* Word 3 -- Number of packets awaiting 1st trans *)
- (* Word 4 -- Number of frames send at least once *)
- (* Word 5 -- Number of retries *)
- (* Word 6 -- Link status # *)
- (*---------------------------------------------------------*)
-
- l_str := '0 0 0 0 0 0' + etb;
- (* 12345678901 *)
- l_str[5] := pk232_dat[5];
- l_str[7] := pk232_dat[5];
- l_str[9] := pk232_dat[6];
- l_str[11] := pk232_dat[3];
- pk232_str := l_str;
- pk232_len := LENGTH(pk232_str) + 3;
-
- END;
- EXIT;
-
- END
- ELSE
- IF pk232_dat[3] = #0 THEN (* 0 = AOK! *)
- BEGIN;
- tnc_type := t_to_h_ok;
- pk232_len := 0;
- EXIT;
- END
- ELSE
- BEGIN;
-
- (*-----------------------------------------------------------*)
- (* Translate response to characters *)
- (*-----------------------------------------------------------*)
-
- tnc_type := t_to_h_badmsg; (* All others are bad news. *)
- CASE ORD(pk232_dat[3]) OF (* Interpret the error code *)
- $00 : pk232_str := '';
- $01 : pk232_str := 'Bad';
- $02 : pk232_str := 'Too many';
- $03 : pk232_str := 'Not enough';
- $04 : pk232_str := 'Too long';
- $05 : pk232_str := 'Range';
- $06 : pk232_str := 'Callsign';
- $07 : pk232_str := 'Unknown command';
- $08 : pk232_str := 'Need VIA';
- $09 : pk232_str := 'Not while connected';
- $0A : pk232_str := 'Need MYCALL';
- $0B : pk232_str := 'Need MYSELCAL';
- $0C : pk232_str := 'Already connected';
- $0D : pk232_str := 'Not while disconnected';
- $0E : pk232_str := 'Different connectees';
- $0F : pk232_str := 'Too many packets outstanding';
- $10 : pk232_str := 'Clock not set';
- $11 : pk232_str := 'Need ALL/NONE/YES/NO';
- $15 : pk232_str := 'Not in this mode';
- ELSE
- BEGIN;
- window_write_critical_i(
- 'PK232 Invalid command response -- '
- + port_chan_s + ' -- ',
- ORD(pk232_dat[3]));
- pk232_str := 'Invalid command response';
- END;
- END;
-
- pk232_len := LENGTH(pk232_str) + 3;
- EXIT;
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Bit bucket *)
- (*-------------------------------------------------------------------*)
-
- window_write_critical_i('Non interpreted response received from PK232'
- + port_chan_s + ' -- '
- + CHR(pk232_ctl)
- + pk232_dat[1]
- + pk232_dat[2],
- ORD(pk232_dat[3]));
-
- tnc_type := t_to_h_badmsg;
-
- END;
-
- END;